<?
/**
 * This page is a simple example to use the Key Density Tool
 * 
 * Fill the form with the remote page and start the analysis
 * For any questions please send me a message into phpclass forum
 * dedicated to this class.
 * Thanks
 * 
 * @author Principe Orazio <orazio.principe@gmail.com>
 */
?>
<html>
    <head>
        <title>Key Density Tool - Example</title>
    </head>
    <body>
        <form method="post" action="">
            <table>
                <tr>
                    <td>Enter the page url</td>
                    <td>
                        <input type="text" name="page_uri" id="page_uri" value="<?=@$_POST['page_url']?>" />
                    </td>
                    <td>
                        <input type="submit" name="cmdAction" value="Get Keywords Density" />
                    </td>
                </tr>
            </table>
        </form>
        <?
        if (!empty($_POST['cmdAction'])) {

            require("KeyDensityTool.php");

            $kdt = new KeyDensityTool();
            $kdt->setUri($_POST['page_uri']);

            //Set max of 3 word to be concatenated
            $kdt->setDeepLenght(3);

            $kdt->run();
            ?>

            <h1>Process page for <?= $kdt->getUri(); ?></h1>

            <h2>
                Density for page:
                Founds <?= $kdt->getWordCount() ?> words
            </h2>

            <p>
                <b>Text processed:</b>
            </p>
            <p><code><?= $kdt->getNoHtmlData() ?></code></p>

            <table>
                <tr>
                    <th>single word</th>
                    <th>two words</th>
                    <th>three words</th>
                </tr>
                <tr>
                    <td style="vertical-align: top; border: 1px solid black">
                        <table cellpadding="4" cellspacing="0">
                            <tr>
                                <th>Word</th>
                                <th>Count</th>
                                <th>Density</th>
                            </tr>
                            <?
                            $res = $kdt->getResults(1);
                            foreach ($res as $keyword => $data):
                                ?>
                                <tr>
                                    <td><?= $keyword ?></td>
                                    <td><?= $data["count"] ?></td>
                                    <td><?= $data["density"] ?>%</td>
                                </tr>
                                <?
                            endforeach;
                            ?>
                        </table>
                    </td>
                    <td style="vertical-align: top; border: 1px solid black">
                        <table cellpadding="4" cellspacing="0">
                            <tr>
                                <th>Word</th>
                                <th>Count</th>
                                <th>Density</th>
                            </tr>
                            <?
                            $res = $kdt->getResults(2);
                            foreach ($res as $keyword => $data):
                                ?>
                                <tr>
                                    <td><?= $keyword ?></td>
                                    <td><?= $data["count"] ?></td>
                                    <td><?= $data["density"] ?>%</td>
                                </tr>
                                <?
                            endforeach;
                            ?>
                        </table>
                    </td>
                    <td style="vertical-align: top; border: 1px solid black">
                        <table cellpadding="4" cellspacing="0">
                            <tr>
                                <th>Word</th>
                                <th>Count</th>
                                <th>Density</th>
                            </tr>
                            <?
                            $res = $kdt->getResults(3);
                            foreach ($res as $keyword => $data):
                                ?>
                                <tr>
                                    <td><?= $keyword ?></td>
                                    <td><?= $data["count"] ?></td>
                                    <td><?= $data["density"] ?>%</td>
                                </tr>
                                <?
                            endforeach;
                            ?>
                        </table>
                    </td>
                </tr>	
            </table>
            <?
        } // end if(!empty($_POST['cmdAction']))
        ?>
    </body>
</html>
